<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>

    // 1.对象取值
    const person = {
        name: "jack",
        age: 21,
        language: ['java', 'js', 'css']
    }

    console.log(Object.keys(person)); //  ["name", "age", "language"]
    console.log(Object.values(person)); // ["jack", 21, Array(3)]
    console.log(Object.entries(person)); // [Array(2), Array(2), Array(2)]


    // 2.对象合并
    const target = {a: 1};
    const source1 = {b: 2};
    const source2 = {c: 3};

    Object.assign(target, source1, source2);
    console.log(target);    // {a: 1, b: 2, c: 3}


    // 3.声明对象简写
    const name = 'zhangsan';
    const age = 23;
    const person2 = {name, age};   //{name: "zhangsan", age: 23}
    console.log(person2);


    // 4、对象属性简写
    let person3 = {
        name: 'jake',
        // 以前写法
        eat: function (food) {
            console.log(this.name + "正在吃" + food);
        },

        // 箭头函数简写，箭头函数中不能使用this
        eat1: (food) => console.log(person3.name + "正在吃" + food),
        // 简写
        eat2(food) {
            console.log(this.name + "正在吃" + food);
        }

    }

    person3.eat("苹果");

    person3.eat1("香蕉");

    person3.eat2("橘子");


    // 5.对象拓展运算

    // 5.1 对象拷贝（深拷贝）
    let p1 = {name: 'amy', age: 12};
    let someone = {...p1};  // {name: "amy", age: 12}
    console.log(someone);

    // 5.2合并对象
    let name1 = {name : 'amy'};
    let age1 = {age : 23};
    let p2 = {name : 'zhangsan'};
    p2 = {...name1, ...age1};
    console.log(p2);  // {name: "amy", age: 23}














</script>

</body>
</html>
